package com.dianrui.qiyouriding.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.dianrui.qiyouriding.R;
import com.dianrui.qiyouriding.bean.ChangeName;
import com.dianrui.qiyouriding.util.StringUtils;
import com.dianrui.qiyouriding.util.ToastUtil;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 修改昵称
 * @author lzy
 */
public class ChangNameActivity extends BaseActivity {
    private String mName;

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.top_right)
    TextView topRight;
    @BindView(R.id.edit_activity_change_info)
    EditText editActivityChangeInfo;


    @Override
    public int getContentViewId() {
        return R.layout.activity_change_name;
    }

    @Override
    public void initView() {
        customInit(true, R.color.main_color);
        if (getIntent() != null && getIntent().getExtras() != null) {
            Bundle bundle=getIntent().getExtras();
            if (bundle != null) {
                mName = bundle.getString("nickname");
            }
        }
        title.setText(getString(R.string.change_name));
        editActivityChangeInfo.setText(mName);
        topRight.setText(getString(R.string.save));
        topRight.setVisibility(View.VISIBLE);
    }

    @Override
    public void initData() {
    }

    @OnClick({R.id.back, R.id.top_right, R.id.name_update_img})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.top_right:
                if (StringUtils.isEmpty(editActivityChangeInfo.getText().toString())) {
                    ToastUtil.showToast(getString(R.string.please_input_names));
                } else {
                    EventBus.getDefault().post(new ChangeName(editActivityChangeInfo.getText().toString().trim()));
                    finish();
                }
                break;

            case R.id.name_update_img:
                editActivityChangeInfo.setText("");
                break;

            default:
                break;
        }
    }
}
